package com.platagalicia.web.controller;

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Controller para recibir el email
 * @author oscarha
 *
 */
public class MailController extends BaseController{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Envio de mail por post.
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
        	String toAdminMail = "platagalicia@yahoo.es";
        	String smtpMail = "platagalicia1@gmail.com";
        	String nombre = getParam(req, "nombre");
            String mail = getParam(req, "email");
            String telefono = getParam(req, "telefono");
            String mensaje = getParam(req, "mensaje");
            MimeMessage msg = new MimeMessage(session);
            msg.setSubject("Contacto platagalicia.es");
            msg.setFrom(new InternetAddress(smtpMail));// a quien responder
            msg.setSender(new InternetAddress(smtpMail));//Quien lo envia
            msg.setContent("Nombre:"+nombre+"<br>Mail: "+mail+"<br>Telefono: "+telefono+"<br>Mensaje:"+mensaje, "text/html");
//            msg.addRecipient(Message.RecipientType.TO, new InternetAddress("oscarha@gmail.com"));//a quien se le va enviar.
            msg.setRecipient(Message.RecipientType.TO, new InternetAddress(toAdminMail));//a quien se le va enviar.
            Transport.send(msg);
        } catch (Exception ae) {
        	
        }
	}

}
